﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BSCMFF.Core.DataAccessLayer;

namespace BSCMFF.Web.UserControls.Details
{
    public partial class EvaluationDetails : System.Web.UI.UserControl
    {
        private Evaluation _eval;// = new Evaluation();

        public Evaluation Evalut
        {
            get
            {
                if (_eval == null)
                {
                    _eval = new Evaluation();
                    int tempID = 0;
                    Int32.TryParse(HiddenFieldID.Value, out tempID);
                    _eval.ID = tempID;
                    _eval.Name = RadTextBoxName.Text;
                    _eval.Description = RadTextBoxDescription.Text;
                    if (RadDatePickerStartDate.SelectedDate != null)
                    {
                        _eval.StartDate = (DateTime)RadDatePickerStartDate.SelectedDate;
                    }
                    if (RadDatePickerEndDate.SelectedDate != null)
                    {
                        _eval.EndDate = (DateTime)RadDatePickerEndDate.SelectedDate;
                    }
                    _eval.Repetition = CheckBoxRepetition.Checked;
                    return _eval;
                }
                else
                {
                    return _eval;
                }
            }
            set
            {
                _eval = value;
            }
        }

        public bool IsEditMode { get; set; }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsEditMode)
            {
                foreach (Control c in this.Controls)
                {
                    if (c.GetType().Name == "RadTextBox")
                    {
                        c.Visible=false;
                        Label l = (Label)this.FindControl(c.ID.Replace("RadTextBox", "LabelCurrent"));
                        l.Visible=true;
                    }
                    if (c.GetType().Name == "RadDatePicker")
                    {
                        c.Visible=false;
                        Label l = (Label)this.FindControl(c.ID.Replace("RadDatePicker", "LabelCurrent"));
                        l.Text = DateTime.Parse(l.Text).ToShortDateString();

                        l.Visible=true;
                    }
                }
                PlaceHolderButtons.Visible = false;
                CheckBoxRepetition.Enabled = false;

                
            }
        }

        protected void RadButtonMonth_Click(object sender, EventArgs e)
        {
            if (RadDatePickerStartDate.SelectedDate != null)
            {
                RadDatePickerEndDate.SelectedDate = RadDatePickerStartDate.SelectedDate.Value.AddMonths(1);
            }
        }

        protected void RadButtonQuarter_Click(object sender, EventArgs e)
        {
            if (RadDatePickerStartDate.SelectedDate != null)
            {
                RadDatePickerEndDate.SelectedDate = RadDatePickerStartDate.SelectedDate.Value.AddMonths(3);
            }
        }

        protected void RadButtonHalfYear_Click(object sender, EventArgs e)
        {
            if (RadDatePickerStartDate.SelectedDate != null)
            {
                RadDatePickerEndDate.SelectedDate = RadDatePickerStartDate.SelectedDate.Value.AddMonths(6);
            }
        }

        protected void RadButtonYear_Click(object sender, EventArgs e)
        {
            if (RadDatePickerStartDate.SelectedDate != null)
            {
                RadDatePickerEndDate.SelectedDate = RadDatePickerStartDate.SelectedDate.Value.AddYears(1);
            }
        }
    }
}